﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LogisticsBLL;
using Model;

namespace WebLosgic.TruckDispaly
{
    public partial class DDTrcuk : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["UserIDs"] != null)
                {
                    int carrid = Convert.ToInt32(Request.QueryString["ID"]);
                    if (carrid != 0)
                    {
                        getBind();
                    }
                    else
                    {
                        Server.Transfer("TruckDispatch.aspx");
                    }
                }
                else
                {
                    Server.Transfer("../login.aspx");
                }
                
                
            }
        }

        public void getBind()
        {
            int pageIndex = AspNetPagerTool.CurrentPageIndex;
            int pageSize = AspNetPagerTool.PageSize;
            int count = 0;
            TruckDispathBLL tb = new TruckDispathBLL();
            RptBindDrive.DataSource = tb.Distach_TruckS(pageIndex, pageSize, out count);
            AspNetPagerTool.RecordCount = count;
            RptBindDrive.DataBind();
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            int UserID = Convert.ToInt32(Session["UserIDs"]);
            int carrid = Convert.ToInt32(Request.QueryString["ID"]);
            int Truckid = Convert.ToInt32(((Button)sender).CommandArgument);
            CarriessCyBLL cb = new CarriessCyBLL();
           
            string result = cb.CarriesSching(carrid,Truckid,UserID);
            
            if (result!="")
            {
                string name = Session["names"].ToString();
                string Behavor = "" + name + ": 添加调度任务";
                int TypeId = 20;
                int UserIDs = Convert.ToInt32(Session["UserIDs"]);
                string Parameters = UserID + "," + carrid + "," + Truckid;
                string ProcName = "p_Carries_Sching";
                HttpRequest request = HttpContext.Current.Request;
                string IP = "192.168.0.1";
                int IsExcePion = 0;
                int a = ProcBLL.InserSys(Behavor, TypeId, UserIDs, Parameters, ProcName, IP, IsExcePion);
                if (a > 0)
                {
                    Page.ClientScript.RegisterStartupScript(GetType(), "", "alert('" + result + "')", true);
                }
                getBind();
            }
        }

        protected void AspNetPagerTool_PageChanged(object sender, EventArgs e)
        {
            getBind();
        }
    }
}